using System.ComponentModel.DataAnnotations;

namespace RiceShop.Models
{
    /// <summary>
    /// 支付记录模型
    /// </summary>
    public class PaymentRecord
    {
        /// <summary>
        /// 支付记录ID
        /// </summary>
        [Key]
        public int PaymentId { get; set; }

        /// <summary>
        /// 订单ID
        /// </summary>
        public long OrderId { get; set; }

        /// <summary>
        /// 订单号
        /// </summary>
        [Required]
        [StringLength(50)]
        public string OrderNo { get; set; } = string.Empty;

        /// <summary>
        /// 支付单号（商户内部支付单号）
        /// </summary>
        [Required]
        [StringLength(50)]
        public string PaymentNo { get; set; } = string.Empty;

        /// <summary>
        /// 微信预支付ID
        /// </summary>
        [StringLength(50)]
        public string? PrepayId { get; set; }

        /// <summary>
        /// 微信支付订单号
        /// </summary>
        [StringLength(50)]
        public string? TransactionId { get; set; }

        /// <summary>
        /// 支付金额
        /// </summary>
        [Required]
        public decimal PaymentAmount { get; set; }

        /// <summary>
        /// 支付状态
        /// 0-待支付 1-支付成功 2-支付失败 3-已关闭 4-已退款
        /// </summary>
        public int PaymentStatus { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        [StringLength(20)]
        public string PaymentMethod { get; set; } = "WXPAY";

        /// <summary>
        /// 支付时间
        /// </summary>
        public DateTime? PaymentTime { get; set; }

        /// <summary>
        /// 支付失败原因
        /// </summary>
        [StringLength(200)]
        public string? FailReason { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 关联的订单
        /// </summary>
        public virtual Order? Order { get; set; }
    }

    /// <summary>
    /// 支付状态枚举
    /// </summary>
    public enum PaymentStatus
    {
        /// <summary>
        /// 待支付
        /// </summary>
        Pending = 0,

        /// <summary>
        /// 支付成功
        /// </summary>
        Success = 1,

        /// <summary>
        /// 支付失败
        /// </summary>
        Failed = 2,

        /// <summary>
        /// 已关闭
        /// </summary>
        Closed = 3,

        /// <summary>
        /// 已退款
        /// </summary>
        Refunded = 4
    }
} 